

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class DataFinalList extends JFrame{
    public DataFinalList(Object[][] data, String[] dataAttribute, boolean onoff,int dataPosition){

        SQLOperation sql=new SQLOperation();

        setTitle("Further Data List");
        Container container=getContentPane();
        setLayout(new BorderLayout());

        JPanel titlePanel=new JPanel();

        JLabel title=new JLabel("Further Data Information of "+((onoff)?"On":"Off"));
        title.setFont(new Font("",Font.BOLD,20));

        titlePanel.add(title);

        add(titlePanel,BorderLayout.NORTH);

        int count=0;
        for(int i=0;i<data.length;i++){
            if(data[i][dataPosition]==(Object) ((onoff)?1:0)){
                count++;
            }
        }
        Object[][] furtherData=new Object[count][data[0].length];
        count=0;
        for(int i=0;i<data.length;i++){
            if(data[i][dataPosition]==(Object) ((onoff)?1:0)){
                for(int j=0;j<data[0].length;j++) furtherData[count][j]=data[i][j];
                count++;
            }
        }

        JTable classList=new JTable(furtherData,dataAttribute);

        classList.setRowHeight(30);
        classList.setFont(new Font("",Font.PLAIN,15));

        classList.setEnabled(true);
        classList.getTableHeader().setFont(new Font("",Font.BOLD,20));
        JScrollPane scrollPane=new JScrollPane(classList);

        add(scrollPane,BorderLayout.CENTER);

        JButton back=new JButton("Back");
        back.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
            }
        });

        JPanel buttons=new JPanel();
        buttons.add(back);

        add(buttons,BorderLayout.SOUTH);


        setSize(600,500);
        setResizable(false);
        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        setVisible(true);



    }
    public DataFinalList(Object[][] data,String[] dataAttribute, boolean largesmall, int index,int dataPosition){
        SQLOperation sql=new SQLOperation();

        setTitle("Further Data List");
        Container container=getContentPane();
        setLayout(new BorderLayout());

        JPanel titlePanel=new JPanel();

        JLabel title=new JLabel("Further Data "+((largesmall)?"More":"Less")+" Than "+index);
        title.setFont(new Font("",Font.BOLD,20));


        titlePanel.add(title);
        add(titlePanel,BorderLayout.NORTH);

        int count=0;
        for(int i=0;i<data.length;i++){

            if((Integer.parseInt((String)data[i][dataPosition]) > (int)index)==largesmall){
                count++;
            }
        }

        Object[][] furtherData=new Object[count][data[0].length];
        count=0;
        for(int i=0;i<data.length;i++){
            if((Integer.parseInt((String)data[i][dataPosition]) > (int)index)==largesmall){
                for(int j=0;j<data[i].length;j++) furtherData[count][j]=data[i][j];

                count++;
            }
        }

        JTable classList=new JTable(furtherData,dataAttribute);

        classList.setRowHeight(30);
        classList.setFont(new Font("",Font.PLAIN,15));

        classList.setEnabled(true);
        classList.getTableHeader().setFont(new Font("",Font.BOLD,20));
        JScrollPane scrollPane=new JScrollPane(classList);

        add(scrollPane,BorderLayout.CENTER);

        JButton back=new JButton("Back");
        back.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
            }
        });

        JPanel buttons=new JPanel();
        buttons.add(back);

        add(buttons,BorderLayout.SOUTH);


        setSize(600,500);
        setResizable(false);
        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        setVisible(true);



    }
}
